package com.polaris.live.ui.party.music

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import com.polaris.live.common.ext.dp
import com.polaris.live.databinding.WidgetMusicEmptyBinding

/**
 * 空音乐数据
 *
 * @author Created by lucas on 2023/10/16 20:42
 * @since 1.0.0
 */
class EmptyMusicView(context: Context, attrs: AttributeSet? = null) : RelativeLayout(context, attrs) {

    private val mBinding = WidgetMusicEmptyBinding.inflate(LayoutInflater.from(context), this)

    fun setEmptyTip(
        @DrawableRes img: Int,
        tip: String,
        @ColorInt color: Int? = null,
        width: Int? = null,
        height: Int? = null,
        showAdd: Boolean = true,
    ) {
        mBinding.bg.setImageResource(img)
        mBinding.text.text = tip
        color?.let { mBinding.text.setTextColor(it) }

        if (width != null && height != null) {
            val layoutParams = mBinding.bg.layoutParams as ViewGroup.LayoutParams
            layoutParams.width = width.dp
            layoutParams.height = height.dp
            mBinding.bg.layoutParams = layoutParams
        }

        if (showAdd) {
            mBinding.addRl.visibility = View.VISIBLE
        } else {
            mBinding.addRl.visibility = View.GONE
        }
    }
}